package com.example.dao;

import com.example.domain.User;
import com.example.utill.JDBCUtills;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao {
    /**
     * 登录方法
     * @param loginin
     * @return user's data
     */
    //声明JDBCTemplate 对象共用
    private JdbcTemplate template = new JdbcTemplate(JDBCUtills.getDataSource());

    public User login(User loginin){
        try {
            String sql = "select * from user where username = ? and password = ?";
            return template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class), loginin.getUsername(), loginin.getPassword());
        }
        catch (DataAccessException e){
            e.printStackTrace();
            return null;
        }
    }
}
